import {
	defineStore
} from 'pinia';

export const orderStore = defineStore('orderStore', {
	state: () => {
		return {
			orderList: []
		};
	},
	// 也可以这样定义
	// state: () => ({ count: 0 })
	actions: {
		addOrder(goods){
			const index = this.orderList.findIndex(item => goods.goodsId == item.goodsId)
			if(index > -1){
				this.orderList.splice(index,1);
			}
			this.orderList.push(goods)
		},
		addOrderList(List){
			List.forEach(goods=>{
				const index = this.orderList.findIndex(item => goods.goodsId == item.goodsId)
				if(index > -1){
					this.orderList.splice(index,1);
				}
				this.orderList.push(goods)
			})
		},
		
	},
});